package com.mxdx.edu.conf;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.jdbc.support.incrementer.MySQLMaxValueIncrementer;

import javax.annotation.Resource;
import javax.sql.DataSource;

/**
 * Created by howie on 16/8/10.
 */
@Configuration
public class SerialIdGenarater {

    @Value("${serialIdGenarater.incrementerName}")
    private String incrementerName;

    @Resource
    private DataSource dataSource;

    @Bean
    public MySQLMaxValueIncrementer mySQLMaxValueIncrementer(){

        MySQLMaxValueIncrementer mysql = new MySQLMaxValueIncrementer();
        mysql.setIncrementerName(incrementerName);
        mysql.setColumnName("serial_id");
        mysql.setCacheSize(10);
        mysql.setDataSource(dataSource);
        return mysql;
    }
}
